<?php
class Reply_model extends MY_Model {

    function __construct(){
        parent::__construct();
        $this->tbl_name = 'edm_orders';
    }

    function add($data){
    	return $this->save('reply',$data);
    }
    
    function get_by_page($tid,$pagenum){
    	
    	$count = $this->db->select('r.id')
    		->from('reply r')
    		->where(array('tid'=>$tid,'is_del'=>0))
    		->count_all_results();
		
    	$this->count = $count;
		
    	$query = $this->db->select('r.*,m.nname as postername,m.email as posteremail')
    		->from('reply r')
    		->join('member m','m.id=r.poster_id','left')
    		->where(array('tid'=>$tid,'is_del'=>0))
    		->limit(REPLY_PAGESIZE,($pagenum-1)*REPLY_PAGESIZE)
    		->order_by('r.atime desc')
    		->get();
		
    		return $query->result();	
    }
    
    function get_count($tid){
    	$count = $this->db->select('r.id')
    		->from('reply r')
    		->where(array('tid'=>$tid,'is_del'=>0))
    		->count_all_results();
		
    	return $count;
    }
    
}